import jsonp from 'common/js/jsonp'
import {commonParams, options} from './config'
import axios from 'axios'

export function getSingerList () {
  const url = 'https://c.y.qq.com/v8/fcg-bin/v8.fcg'

  const data = Object.assign({}, commonParams, {
    channel: 'singer',
    page: 'list',
    key: 'all_all_all',
    pagesize: 1000,
    pagenum: 1,
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq'
  })

  return jsonp(url, data, options)
}

export function getSingerDetail (singerId) {
  const url = 'https://c.y.qq.com/v8/fcg-bin/fcg_v8_singer_track_cp.fcg'

  const data = Object.assign({}, commonParams, {
    hostUin: 0,
    needNewCode: 0,
    platform: 'yqq',
    order: 'listen',
    begin: 0,
    num: 100,
    songstatus: 1,
    singermid: singerId
  })

  return jsonp(url, data, options)
}

/**
 * 获取vkey
 */
export function getVkey (mid) {
  const url = '/api/getVkey'

  const data = Object.assign({}, {
    '-': 'getplaysongvkey015120047843255824',
    g_tk: '5381',
    loginUin: '1479765569',
    hostUin: 0,
    format: 'json',
    inCharset: 'utf8',
    outCharset: 'utf-8',
    notice: 0,
    platform: 'yqq.json',
    needNewCode: 0,
    data: {req: {module: 'CDN.SrfCdnDispatchServer', method: 'GetCdnDispatch', param: {guid: '229603224', calltype: 0, userip: ''}}, req_0: {module: 'vkey.GetVkeyServer', method: 'CgiGetVkey', param: {guid: '229603224', songmid: [mid], songtype: [0], uin: '1479765569', loginflag: 1, platform: '20'}}, comm: {uin: 1479765569, format: 'json', ct: 24, 'cv': 0}}
  })

  return axios.get(url, {
    params: data
  }).then((res) => {
    return Promise.resolve(res.data)
  })
}
